"""
应用配置管理
"""
import os
from typing import List
from pydantic_settings import BaseSettings
from pydantic import Field


class Settings(BaseSettings):
    """应用配置类"""
    
    # 应用基础配置
    app_name: str = Field(default="AI日记", env="APP_NAME")
    debug: bool = Field(default=True, env="DEBUG")
    host: str = Field(default="0.0.0.0", env="HOST")
    port: int = Field(default=8000, env="PORT")
    
    # 数据库配置
    database_url: str = Field(env="DATABASE_URL")
    
    # JWT配置
    secret_key: str = Field(env="SECRET_KEY")
    algorithm: str = Field(default="HS256", env="ALGORITHM")
    access_token_expire_minutes: int = Field(default=30, env="ACCESS_TOKEN_EXPIRE_MINUTES")
    
    # 阿里云百炼配置
    dashscope_api_key: str = Field(env="DASHSCOPE_API_KEY")
    dashscope_base_url: str = Field(default="https://dashscope.aliyuncs.com/compatible-mode/v1", env="DASHSCOPE_BASE_URL")
    
    # CORS配置
    allowed_origins: str = Field(
        default="http://localhost:3000,http://127.0.0.1:3000,http://114.215.173.182:3000", 
        env="ALLOWED_ORIGINS"
    )
    
    @property
    def allowed_origins_list(self) -> List[str]:
        """将CORS配置转换为列表"""
        return [origin.strip() for origin in self.allowed_origins.split(",")]
    
    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"


# 创建配置实例
settings = Settings() 